<!DOCTYPE html><html><head><title>第12期第一周课后练习作业</title><meta charset='utf-8'><link href='https://dn-maxiang.qbox.me/res-min/themes/marxico.css' rel='stylesheet'><style>.note-content  {font-family: 'Helvetica Neue', Arial, 'Hiragino Sans GB', STHeiti, 'Microsoft YaHei', 'WenQuanYi Micro Hei', SimSun, Song, sans-serif;}


</style></head><body><div id='preview-contents' class='note-content'>
                        
                    

<h2 id="第12期第一周课后练习作业">第12期第一周课后练习作业</h2>

<p></p>

<blockquote>
  <p>建议大家每一道题都要画图（尤其是复杂一些的题目），画图过程能让我们把基础知识掌握的更加扎实，而且更加有效的算出正确的答案</p>
  
  <p>先自己计算，都完成后在开始测试答案，千万不要直接的输出看答案，这样就没有意义了</p>
</blockquote>

<h3 id="一选择题">一、选择题</h3>

<p>1、</p>

<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-built_in">console</span>.log(a); 
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span><span class="hljs-keyword">var</span> a=<span class="hljs-number">12</span>; 
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    <span class="hljs-built_in">console</span>.log(a); 
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>    <span class="hljs-keyword">var</span> a=<span class="hljs-number">13</span>;   
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>fn();   
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span><span class="hljs-built_in">console</span>.log(a);
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span><span class="hljs-comment">/*
</span></div><div class="hljs-line"><span class="hljs-comment line-number">11.</span> A、undefined  12 13             
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span> B、undefined undefined 12   
</div><div class="hljs-line"><span class="hljs-comment line-number">13.</span> C、undefined undefined 13         
</div><div class="hljs-line"><span class="hljs-comment line-number">14.</span> D、有程序报错
</div><div class="hljs-line"><span class="hljs-comment line-number">15.</span>*/
</div></code></pre>

<p>2、</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-built_in">console</span>.log(a); 
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span><span class="hljs-keyword">var</span> a=<span class="hljs-number">12</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    <span class="hljs-built_in">console</span>.log(a);
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>    a=<span class="hljs-number">13</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>fn();
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span><span class="hljs-built_in">console</span>.log(a);
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span><span class="hljs-comment">/*
</span></div><div class="hljs-line"><span class="hljs-comment line-number">11.</span> A、undefined  12 13             
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span> B、undefined undefined 12   
</div><div class="hljs-line"><span class="hljs-comment line-number">13.</span> C、undefined undefined 13         
</div><div class="hljs-line"><span class="hljs-comment line-number">14.</span> D、有程序报错
</div><div class="hljs-line"><span class="hljs-comment line-number">15.</span>*/
</div></code></pre>

<p>3、</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-built_in">console</span>.log(a);
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span>a=<span class="hljs-number">12</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    <span class="hljs-built_in">console</span>.log(a);
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>    a=<span class="hljs-number">13</span>;   
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>fn();
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span><span class="hljs-built_in">console</span>.log(a);
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span><span class="hljs-comment">/*
</span></div><div class="hljs-line"><span class="hljs-comment line-number">11.</span> A、undefined  12 13             
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span> B、undefined undefined 12   
</div><div class="hljs-line"><span class="hljs-comment line-number">13.</span> C、undefined undefined 13         
</div><div class="hljs-line"><span class="hljs-comment line-number">14.</span> D、有程序报错
</div><div class="hljs-line"><span class="hljs-comment line-number">15.</span>*/
</div></code></pre>

<p>4、</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">var</span> foo=<span class="hljs-number">1</span>; 
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bar</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>    <span class="hljs-keyword">if</span>(!foo){
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>        <span class="hljs-keyword">var</span> foo=<span class="hljs-number">10</span>; 
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>    }
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>    <span class="hljs-built_in">console</span>.log(foo); 
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span>bar();
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span><span class="hljs-comment">/*
</span></div><div class="hljs-line"><span class="hljs-comment line-number">11.</span> A、1     
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span> B、10     
</div><div class="hljs-line"><span class="hljs-comment line-number">13.</span> C、undefined    
</div><div class="hljs-line"><span class="hljs-comment line-number">14.</span> D、报错
</div><div class="hljs-line"><span class="hljs-comment line-number">15.</span>*/
</div></code></pre>

<p>5、</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">var</span> n=<span class="hljs-number">0</span>; 
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">a</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>    <span class="hljs-keyword">var</span> n=<span class="hljs-number">10</span>; 
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">b</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>        n++; 
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>        <span class="hljs-built_in">console</span>.log(n); 
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>    }
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span>    b();
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span>    <span class="hljs-keyword">return</span> b; 
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">11.</span><span class="hljs-keyword">var</span> c=a();
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span>c(); 
</div><div class="hljs-line"><span class="hljs-comment line-number">13.</span><span class="hljs-built_in">console</span>.log(n);
</div><div class="hljs-line"><span class="hljs-comment line-number">14.</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">15.</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">16.</span><span class="hljs-comment">/*
</span></div><div class="hljs-line"><span class="hljs-comment line-number">17.</span> A、1 1 1   
</div><div class="hljs-line"><span class="hljs-comment line-number">18.</span> B、11 11 0  
</div><div class="hljs-line"><span class="hljs-comment line-number">19.</span> C、11 12 0  
</div><div class="hljs-line"><span class="hljs-comment line-number">20.</span> D、11 12 12
</div><div class="hljs-line"><span class="hljs-comment line-number">21.</span>*/
</div></code></pre>

<p>6、</p>

<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">var</span> a=<span class="hljs-number">10</span>,b=<span class="hljs-number">11</span>,c=<span class="hljs-number">12</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test</span>(<span class="hljs-params">a</span>)</span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>     a=<span class="hljs-number">1</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>     <span class="hljs-keyword">var</span> b=<span class="hljs-number">2</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>     c=<span class="hljs-number">3</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>test(<span class="hljs-number">10</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span><span class="hljs-built_in">console</span>.log(a);  
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span><span class="hljs-built_in">console</span>.log(b);   
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span><span class="hljs-built_in">console</span>.log(c);
</div><div class="hljs-line"><span class="hljs-comment line-number">11.</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span><span class="hljs-comment">/*
</span></div><div class="hljs-line"><span class="hljs-comment line-number">13.</span> A、1 11 3   
</div><div class="hljs-line"><span class="hljs-comment line-number">14.</span> B、10 11 12  
</div><div class="hljs-line"><span class="hljs-comment line-number">15.</span> C、1 2 3   
</div><div class="hljs-line"><span class="hljs-comment line-number">16.</span> D、10 11 3
</div><div class="hljs-line"><span class="hljs-comment line-number">17.</span>*/
</div></code></pre>

<p>7、</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">if</span>(!(<span class="hljs-string">"a"</span> <span class="hljs-keyword">in</span> <span class="hljs-built_in">window</span>)){
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span>   <span class="hljs-keyword">var</span> a=<span class="hljs-number">1</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span><span class="hljs-built_in">console</span>.log(a);
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span><span class="hljs-comment">/*
</span></div><div class="hljs-line"><span class="hljs-comment line-number">7.</span> A、1   
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span> B、undefined   
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span> C、报错   
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span> D、以上答案都不对
</div><div class="hljs-line"><span class="hljs-comment line-number">11.</span>*/
</div></code></pre>

<p>8、</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">var</span> a=<span class="hljs-number">4</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">b</span>(<span class="hljs-params">x,y,a</span>) </span>{    
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>     <span class="hljs-built_in">console</span>.log(a); 
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>     <span class="hljs-built_in">arguments</span>[<span class="hljs-number">2</span>]=<span class="hljs-number">10</span>;        
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>     <span class="hljs-built_in">console</span>.log(a); 
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>a=b(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>);   
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span><span class="hljs-built_in">console</span>.log(a); 
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span><span class="hljs-comment">/*
</span></div><div class="hljs-line"><span class="hljs-comment line-number">11.</span> A、3  3  4   
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span> B、3  10  4   
</div><div class="hljs-line"><span class="hljs-comment line-number">13.</span> C、3  10  10   
</div><div class="hljs-line"><span class="hljs-comment line-number">14.</span> D、3  10  undefined
</div><div class="hljs-line"><span class="hljs-comment line-number">15.</span>*/
</div></code></pre>

<p>9、</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">var</span> foo=<span class="hljs-string">'hello'</span>; 
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">foo</span>)</span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>   <span class="hljs-built_in">console</span>.log(foo);
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>   <span class="hljs-keyword">var</span> foo=foo||<span class="hljs-string">'world'</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>   <span class="hljs-built_in">console</span>.log(foo);
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>})(foo);
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span><span class="hljs-built_in">console</span>.log(foo);
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span><span class="hljs-comment">/*
</span></div><div class="hljs-line"><span class="hljs-comment line-number">10.</span> A、hello hello hello   
</div><div class="hljs-line"><span class="hljs-comment line-number">11.</span> B、undefined world  hello   
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span> C、hello world world   
</div><div class="hljs-line"><span class="hljs-comment line-number">13.</span> D、以上答案都不正确
</div><div class="hljs-line"><span class="hljs-comment line-number">14.</span>*/
</div></code></pre>

<p>10、</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">var</span> a=<span class="hljs-number">9</span>; 
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params"></span>)</span>{ 
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>    a=<span class="hljs-number">0</span>;       
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">b</span>)</span>{ 
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>        <span class="hljs-keyword">return</span> b+a++; 
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>    }    
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span><span class="hljs-keyword">var</span> f=fn();
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span><span class="hljs-built_in">console</span>.log(f(<span class="hljs-number">5</span>));
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span><span class="hljs-built_in">console</span>.log(fn()(<span class="hljs-number">5</span>));
</div><div class="hljs-line"><span class="hljs-comment line-number">11.</span><span class="hljs-built_in">console</span>.log(f(<span class="hljs-number">5</span>));
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span><span class="hljs-built_in">console</span>.log(a);
</div><div class="hljs-line"><span class="hljs-comment line-number">13.</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">14.</span><span class="hljs-comment">/*
</span></div><div class="hljs-line"><span class="hljs-comment line-number">15.</span> A、6 6 7 2   
</div><div class="hljs-line"><span class="hljs-comment line-number">16.</span> B、5 6 7 3   
</div><div class="hljs-line"><span class="hljs-comment line-number">17.</span> C、5 5 6 3   
</div><div class="hljs-line"><span class="hljs-comment line-number">18.</span> D、以上答案都不正确 
</div><div class="hljs-line"><span class="hljs-comment line-number">19.</span>*/
</div></code></pre>

<h3 id="二问答题需要画图">二、问答题（需要画图）</h3>

<p>1、</p>

<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">var</span> ary=[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>];
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params">ary</span>)</span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>    ary[<span class="hljs-number">0</span>]=<span class="hljs-number">0</span>;    
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    ary=[<span class="hljs-number">0</span>];    
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>    ary[<span class="hljs-number">0</span>]=<span class="hljs-number">100</span>;    
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>    <span class="hljs-keyword">return</span> ary; 
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span><span class="hljs-keyword">var</span> res=fn(ary);    
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span><span class="hljs-built_in">console</span>.log(ary);    
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span><span class="hljs-built_in">console</span>.log(res);
</div></code></pre>

<p>2、</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params">i</span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span>    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>        <span class="hljs-built_in">console</span>.log(n + (i++));
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    }
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span><span class="hljs-keyword">var</span> f = fn(<span class="hljs-number">10</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>f(<span class="hljs-number">20</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span>fn(<span class="hljs-number">20</span>)(<span class="hljs-number">40</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span>fn(<span class="hljs-number">30</span>)(<span class="hljs-number">50</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span>f(<span class="hljs-number">30</span>);
</div></code></pre>

<p>3、</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">var</span> i = <span class="hljs-number">10</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>        <span class="hljs-built_in">console</span>.log(n + (++i));
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>    }
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span><span class="hljs-keyword">var</span> f = fn();
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span>f(<span class="hljs-number">20</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span>fn()(<span class="hljs-number">20</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span>fn()(<span class="hljs-number">30</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">11.</span>f(<span class="hljs-number">30</span>);
</div></code></pre>

<p>4、</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">var</span> num = <span class="hljs-number">10</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span><span class="hljs-keyword">var</span> obj = {<span class="hljs-attr">num</span>: <span class="hljs-number">20</span>};
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>obj.fn = (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">num</span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    <span class="hljs-keyword">this</span>.num = num * <span class="hljs-number">3</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>    num++;
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>        <span class="hljs-keyword">this</span>.num += n;
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span>        num++;
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span>        <span class="hljs-built_in">console</span>.log(num);
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span>    }
</div><div class="hljs-line"><span class="hljs-comment line-number">11.</span>})(obj.num);
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span><span class="hljs-keyword">var</span> fn = obj.fn;
</div><div class="hljs-line"><span class="hljs-comment line-number">13.</span>fn(<span class="hljs-number">5</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">14.</span>obj.fn(<span class="hljs-number">10</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">15.</span><span class="hljs-built_in">console</span>.log(num, obj.num);
</div></code></pre>

<p>5、</p>

<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Fn</span>(<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span>    <span class="hljs-keyword">this</span>.x = <span class="hljs-number">100</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>    <span class="hljs-keyword">this</span>.y = <span class="hljs-number">200</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    <span class="hljs-keyword">this</span>.getX = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>        <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.x);
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>    }
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span>Fn.prototype.getX = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span>    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.x);
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span>};
</div><div class="hljs-line"><span class="hljs-comment line-number">11.</span>Fn.prototype.getY = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span>    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.y);
</div><div class="hljs-line"><span class="hljs-comment line-number">13.</span>};
</div><div class="hljs-line"><span class="hljs-comment line-number">14.</span><span class="hljs-keyword">var</span> f1 = <span class="hljs-keyword">new</span> Fn;
</div><div class="hljs-line"><span class="hljs-comment line-number">15.</span><span class="hljs-keyword">var</span> f2 = <span class="hljs-keyword">new</span> Fn;
</div><div class="hljs-line"><span class="hljs-comment line-number">16.</span><span class="hljs-built_in">console</span>.log(f1.getX === f2.getX);
</div><div class="hljs-line"><span class="hljs-comment line-number">17.</span><span class="hljs-built_in">console</span>.log(f1.getY === f2.getY);
</div><div class="hljs-line"><span class="hljs-comment line-number">18.</span><span class="hljs-built_in">console</span>.log(f1.__proto__.getY === Fn.prototype.getY);
</div><div class="hljs-line"><span class="hljs-comment line-number">19.</span><span class="hljs-built_in">console</span>.log(f1.__proto__.getX === f2.getX);
</div><div class="hljs-line"><span class="hljs-comment line-number">20.</span><span class="hljs-built_in">console</span>.log(f1.getX === Fn.prototype.getX);
</div><div class="hljs-line"><span class="hljs-comment line-number">21.</span><span class="hljs-built_in">console</span>.log(f1.constructor);
</div><div class="hljs-line"><span class="hljs-comment line-number">22.</span><span class="hljs-built_in">console</span>.log(Fn.prototype.__proto__.constructor);
</div><div class="hljs-line"><span class="hljs-comment line-number">23.</span>f1.getX();
</div><div class="hljs-line"><span class="hljs-comment line-number">24.</span>f1.__proto__.getX();
</div><div class="hljs-line"><span class="hljs-comment line-number">25.</span>f2.getY();
</div><div class="hljs-line"><span class="hljs-comment line-number">26.</span>Fn.prototype.getY();
</div></code></pre>

<h3 id="三附加思考题面试题">三：附加思考题（面试题）</h3>

<p>1、以下代码的功能是要实现为5个input按钮循环绑定click点击事件，绑定完成后点击1、2、3、4、5五个按钮分别会alert输出0、1、2、3、4五个字符。（腾讯）</p>

<ul><li>请问如下代码是否能实现？</li>
<li>如果不能实现那么现在的效果是什么样的？</li>
<li>应该做怎样的修改才能达到我们想要的效果，并说明原理？  </li>
</ul>

<pre class="prettyprint with-line-number hljs-dark"><code class="hljs xml"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"btnBox"</span>&gt;</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span>    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"button_1"</span> /&gt;</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"button_2"</span> /&gt;</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"button_3"</span> /&gt;</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"button_4"</span> /&gt;</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"button_5"</span> /&gt;</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/javascript"</span>&gt;</span><span class="javascript">
</span></div><div class="hljs-line"><span class="hljs-comment line-number">10.</span>    <span class="hljs-keyword">var</span> btnBox=<span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'btnBox'</span>),
</div><div class="hljs-line"><span class="hljs-comment line-number">11.</span>        inputs=btnBox.getElementsByTagName(<span class="hljs-string">'input'</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span>    <span class="hljs-keyword">var</span> l=inputs.length;
</div><div class="hljs-line"><span class="hljs-comment line-number">13.</span>    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">var</span> i=<span class="hljs-number">0</span>;i&lt;l;i++){
</div><div class="hljs-line"><span class="hljs-comment line-number">14.</span>        inputs[i].onclick=<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">15.</span>            alert(i);
</div><div class="hljs-line"><span class="hljs-comment line-number">16.</span>        }
</div><div class="hljs-line"><span class="hljs-comment line-number">17.</span>    }
</div><div class="hljs-line"><span class="hljs-comment line-number">18.</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</div></code></pre>

<p>2、用友面试题</p>

<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">var</span> fullName=<span class="hljs-string">'language'</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span><span class="hljs-keyword">var</span> obj={
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>    fullName=<span class="hljs-string">'javascript'</span>,
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    <span class="hljs-attr">prop</span>:{
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>        <span class="hljs-attr">getFullName</span>:<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>            <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.fullName;
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>        }
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span>    }
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span>};
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span><span class="hljs-built_in">console</span>.log(obj.prop.getFullName());
</div><div class="hljs-line"><span class="hljs-comment line-number">11.</span><span class="hljs-keyword">var</span> test=obj.prop.getFullName;
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span><span class="hljs-built_in">console</span>.log(test());
</div></code></pre>

<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-keyword">var</span> name=<span class="hljs-string">'window'</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span><span class="hljs-keyword">var</span> Tom={
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>    <span class="hljs-attr">name</span>:<span class="hljs-string">"Tom"</span>,
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    <span class="hljs-attr">show</span>:<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>        <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.name);
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>    },
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>    <span class="hljs-attr">wait</span>:<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span>        <span class="hljs-keyword">var</span> fun=<span class="hljs-keyword">this</span>.show;
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span>        fun();
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span>    }
</div><div class="hljs-line"><span class="hljs-comment line-number">11.</span>};
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span>Tom.wait();
</div></code></pre>

<p>3、阿里超经典面试题（有难度）</p>

<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Foo</span>(<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span>    getName = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>        <span class="hljs-built_in">console</span>.log(<span class="hljs-number">1</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>    };
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>Foo.getName = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span>    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">2</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span>};
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span>Foo.prototype.getName = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">11.</span>    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">3</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span>};
</div><div class="hljs-line"><span class="hljs-comment line-number">13.</span><span class="hljs-keyword">var</span> getName = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">14.</span>    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">4</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">15.</span>};
</div><div class="hljs-line"><span class="hljs-comment line-number">16.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getName</span>(<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">17.</span>    <span class="hljs-built_in">console</span>.log(<span class="hljs-number">5</span>);
</div><div class="hljs-line"><span class="hljs-comment line-number">18.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">19.</span>
</div><div class="hljs-line"><span class="hljs-comment line-number">20.</span>Foo.getName();
</div><div class="hljs-line"><span class="hljs-comment line-number">21.</span>getName();
</div><div class="hljs-line"><span class="hljs-comment line-number">22.</span>Foo().getName();
</div><div class="hljs-line"><span class="hljs-comment line-number">23.</span>getName();
</div><div class="hljs-line"><span class="hljs-comment line-number">24.</span><span class="hljs-keyword">new</span> Foo.getName();
</div><div class="hljs-line"><span class="hljs-comment line-number">25.</span><span class="hljs-keyword">new</span> Foo().getName();
</div><div class="hljs-line"><span class="hljs-comment line-number">26.</span><span class="hljs-keyword">new</span> <span class="hljs-keyword">new</span> Foo().getName();
</div></code></pre>

<p>4、腾讯面试题</p>



<pre class="prettyprint with-line-number hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment line-number">1.</span><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fun</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">2.</span>    <span class="hljs-keyword">this</span>.a=<span class="hljs-number">0</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">3.</span>    <span class="hljs-keyword">this</span>.b=<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">4.</span>        alert(<span class="hljs-keyword">this</span>.a);
</div><div class="hljs-line"><span class="hljs-comment line-number">5.</span>    }
</div><div class="hljs-line"><span class="hljs-comment line-number">6.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">7.</span>fun.prototype={
</div><div class="hljs-line"><span class="hljs-comment line-number">8.</span>    <span class="hljs-attr">b</span>:<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">9.</span>        <span class="hljs-keyword">this</span>.a=<span class="hljs-number">20</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">10.</span>        alert(<span class="hljs-keyword">this</span>.a);
</div><div class="hljs-line"><span class="hljs-comment line-number">11.</span>    },
</div><div class="hljs-line"><span class="hljs-comment line-number">12.</span>    <span class="hljs-attr">c</span>:<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line"><span class="hljs-comment line-number">13.</span>        <span class="hljs-keyword">this</span>.a=<span class="hljs-number">30</span>;
</div><div class="hljs-line"><span class="hljs-comment line-number">14.</span>        alert(<span class="hljs-keyword">this</span>.a)
</div><div class="hljs-line"><span class="hljs-comment line-number">15.</span>    }
</div><div class="hljs-line"><span class="hljs-comment line-number">16.</span>}
</div><div class="hljs-line"><span class="hljs-comment line-number">17.</span><span class="hljs-keyword">var</span> my_fun=<span class="hljs-keyword">new</span> fun();
</div><div class="hljs-line"><span class="hljs-comment line-number">18.</span>my_fun.b();
</div><div class="hljs-line"><span class="hljs-comment line-number">19.</span>my_fun.c();
</div></code></pre>

<p>5、如何实现数组去重？（乐视TV）</p>

<p>6、document.parentNode 和 document.parentnode 的区别？（腾讯）</p>

<p>7、怎么规避多人开发函数重名的问题？（百度搜索）</p>

<p>8、JavaScript如何实现面向对象中的继承？ （百度移动）</p>

<p>9、你理解的闭包作用是什么，优缺点？（乐视）</p>

<blockquote>
  <p><strong>趣味题（乐视）</strong> <br>
  有这样一个村庄，村里的每一个丈夫都背着妻子偷情，村里的每个妻子都知道除了自己丈夫以外的男人偷情，村里有一个规定，如果妻子知道自己的丈夫偷情必须当天处决。有一天村里的女头领说村里有一个丈夫偷情，接下来会发生什么？</p>
</blockquote></div></body></html>